package com.md.mainpage.presenter

import com.md.basedpc.base.BasePresenter
import com.md.mainpage.interfaces.AlbumContract
import com.md.mainpage.interfaces.SearchContract
import com.md.mainpage.model.SearchModel
import com.md.network.api.SearchResult

class SearchPresenter : BasePresenter<SearchContract.View>(), SearchContract.Presenter {

    private val model: SearchModel by lazy {
        SearchModel()
    }

    override fun search(page: Int, size: Int, keyWord: String) {
        checkViewAttached()
        val disposable = model.search(page, size, keyWord).subscribe({ searchResult ->
            mRootView?.apply {
                showResult(keyWord, searchResult)
            }
        }, { throwable ->
            mRootView?.apply {
                showError(throwable.toString())
            }

        })
        disposable?.let { addSubscription(it) }
    }
}